package cn.edu.sgu.www.mhxysy.controller.wenshi;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.entity.wenshi.WenshiViewAttribute;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.wenshi.WenshiViewAttributeService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "纹饰预览属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/wenshi_view_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class WengshiViewAttributeController {

	private final WenshiViewAttributeService wenshiViewAttributeService;

	@Autowired
	public WengshiViewAttributeController(WenshiViewAttributeService wenshiViewAttributeService) {
		this.wenshiViewAttributeService = wenshiViewAttributeService;
	}

	@ApiOperation("查询全部纹饰预览属性")
	@RequestMapping(value = "/selectAll", method = RequestMethod.GET)
	public JsonResult<List<WenshiViewAttribute>> selectAll() {
		List<WenshiViewAttribute> list = wenshiViewAttributeService.selectAll();

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过ID查询纹饰预览属性名称")
	@RequestMapping(value = "/selectNameById", method = RequestMethod.GET)
	public JsonResult<String> selectNameById(
			@ApiParam(name = "id", value = "纹饰预览属性ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		String name = wenshiViewAttributeService.selectNameById(id);

		return JsonResult.success(null, name);
	}

	@ApiOperation("通过纹饰类型ID查询纹饰预览属性")
	@RequestMapping(value = "/selectByWenshiId", method = RequestMethod.GET)
	public JsonResult<List<WenshiViewAttribute>> selectByWenshiId(
			@ApiParam(name = "wenshiId", value = "纹饰类型ID", required = true)
			@NotNull(message = "纹饰类型" + CustomMessages.ID_NOT_NULL) Integer wenshiId) {
		List<WenshiViewAttribute> list = wenshiViewAttributeService.selectByWenshiId(wenshiId);

		return JsonResult.success(null, list);
	}

}